package ejb.entity;

import java.io.Serializable;
import javax.persistence.*;


import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.util.Set;


/**
 * The persistent class for the users database table.
 * 
 */
@Entity
@Table(name="users")
@NamedQueries({
	@NamedQuery(name="DefaultUser.findAll", query="SELECT usr FROM DefaultUser usr"),
	@NamedQuery(name="DefaultUser.findById", query="SELECT usr FROM DefaultUser usr where usr.userId = :id"),
	@NamedQuery(name="DefaultUser.findByLogin", query="SELECT usr FROM DefaultUser usr where usr.userName = :login"),
	@NamedQuery(name="DefaultUser.findByCode", query="SELECT usr FROM DefaultUser usr where usr.code = :code")
})
public class DefaultUser implements Serializable, User {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="user_id")
	private int userId;

	private byte active;
	
	private boolean forecast;
	
	@Column(name="date_created")
	private Timestamp dateCreated;

	private String email;
	
	@Column(name="first_name")
	private String firstName;

	@Column(name="last_name")
	private String lastName;

	private String password;

	@Column(name="user_name")
	private String userName;

	//bi-directional many-to-one association to DefaultPosition
	@OneToMany(mappedBy="user", targetEntity=DefaultPosition.class)
	private Set<Position> positions;
	
	private String code;
	
    /* (non-Javadoc)
	 * @see ejb.entity.User#getCode()
	 */
    @Override
	public String getCode() {
		return code;
	}

	/* (non-Javadoc)
	 * @see ejb.entity.User#setCode(java.lang.String)
	 */
	@Override
	public void setCode(String code) {
		this.code = code;
	}

	public DefaultUser() {
    }

    public DefaultUser(String user_name, String last_name, String first_name, String password, String email, String code) {
    	Calendar calendar = Calendar.getInstance();
    	Date now = calendar.getTime();
    	
    	this.userName = user_name;
    	this.lastName = last_name;
    	this.firstName = first_name;
    	this.password = password;
    	this.email = email;
    	this.active = 0;    	
    	this.dateCreated = new Timestamp(now.getTime());
    	this.code = code;
    }
    
	/* (non-Javadoc)
	 * @see ejb.entity.User#getUserId()
	 */
	@Override
	public int getUserId() {
		return this.userId;
	}

	/* (non-Javadoc)
	 * @see ejb.entity.User#setUserId(int)
	 */
	@Override
	public void setUserId(int userId) {
		this.userId = userId;
	}

	/* (non-Javadoc)
	 * @see ejb.entity.User#getActive()
	 */
	@Override
	public byte getActive() {
		return this.active;
	}

	/* (non-Javadoc)
	 * @see ejb.entity.User#setActive(byte)
	 */
	@Override
	public void setActive(byte active) {
		this.active = active;
	}

	/* (non-Javadoc)
	 * @see ejb.entity.User#getDateCreated()
	 */
	@Override
	public Timestamp getDateCreated() {
		return this.dateCreated;
	}

	/* (non-Javadoc)
	 * @see ejb.entity.User#setDateCreated(java.sql.Timestamp)
	 */
	@Override
	public void setDateCreated(Timestamp dateCreated) {
		this.dateCreated = dateCreated;
	}

	/* (non-Javadoc)
	 * @see ejb.entity.User#getEmail()
	 */
	@Override
	public String getEmail() {
		return this.email;
	}

	/* (non-Javadoc)
	 * @see ejb.entity.User#setEmail(java.lang.String)
	 */
	@Override
	public void setEmail(String email) {
		this.email = email;
	}

	/* (non-Javadoc)
	 * @see ejb.entity.User#getFirstName()
	 */
	@Override
	public String getFirstName() {
		return this.firstName;
	}

	/* (non-Javadoc)
	 * @see ejb.entity.User#setFirstName(java.lang.String)
	 */
	@Override
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	/* (non-Javadoc)
	 * @see ejb.entity.User#getLastName()
	 */
	@Override
	public String getLastName() {
		return this.lastName;
	}

	/* (non-Javadoc)
	 * @see ejb.entity.User#setLastName(java.lang.String)
	 */
	@Override
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	/* (non-Javadoc)
	 * @see ejb.entity.User#getPassword()
	 */
	@Override
	public String getPassword() {
		return this.password;
	}

	/* (non-Javadoc)
	 * @see ejb.entity.User#setPassword(java.lang.String)
	 */
	@Override
	public void setPassword(String password) {
		this.password = password;
	}

	/* (non-Javadoc)
	 * @see ejb.entity.User#getUserName()
	 */
	@Override
	public String getUserName() {
		return this.userName;
	}

	/* (non-Javadoc)
	 * @see ejb.entity.User#setUserName(java.lang.String)
	 */
	@Override
	public void setUserName(String userName) {
		this.userName = userName;
	}

	/* (non-Javadoc)
	 * @see ejb.entity.User#getPositions()
	 */
	@Override
	public Set<Position> getPositions() {
		return this.positions;
	}

	/* (non-Javadoc)
	 * @see ejb.entity.User#setPositions(java.util.Set)
	 */
	@Override
	public void setPositions(Set<Position> positions) {
		this.positions = positions;
	}
	
	@Override
	public boolean isForecast() {
		return forecast;
	}
	@Override
	public void setForecast(boolean forecast) {
		this.forecast = forecast;
	}


	
}